package com.ysre.wolf;

import com.ysre.sheep.Sheep;

public class Wolf {

    private String name;

    private int attack;

    private boolean alive = true;

    public Wolf(String name, int attack){
        this.name = name;
        this.attack = attack;
    }

    public String getName(){
        return this.name;
    }

    public boolean isAlive(){
        return this.alive;
    }

    public boolean attack(Sheep sheep){
        System.out.println(this.getName() +" 狩猎 " + sheep.getName());
        if(this.attack >= sheep.getDefense()){//假设相同攻击下,狼强一点.免得最后剩1羊1狼,谁都打不死谁
            sheep.die();
        }else{
            this.die();
        }
        return this.alive;
    }

    public void die(){
        if(!this.alive) {
            throw new RuntimeException(this.name + "早就死球了");
        }
        this.alive = false;
    }

    public String toString(){
        return name + "攻击:" + attack + " 存活:" + alive;
    }
}
